//
//  ZGLEpisodeVC.m
//  Faker
//
//  Created by dllo on 15/11/9.
//  Copyright © 2015年 dllo. All rights reserved.
//

#import "ZGLEpisodeVC.h"
#import "ZGLEpisodeCell.h"


@interface ZGLEpisodeVC () <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *episodeTableView;

@end

@implementation ZGLEpisodeVC

- (void)dealloc {
    _episodeTableView.dataSource = nil;
    _episodeTableView.delegate = nil;
}
- (void)viewWillAppear:(BOOL)animated {
    self.view.backgroundColor = backColor;
    self.episodeTableView.backgroundColor = foreColor;
    self.tabBarController.tabBar.hidden = YES;
}

- (void)setNavigationBar {
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName, [UIFont fontWithName:@"AmericanTypewriter-Bold" size:20], NSFontAttributeName, nil]];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"zaihufanhui"] style:(UIBarButtonItemStyleDone) target:self action:@selector(leftBarButtonItem:)];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
    self.view.backgroundColor = [UIColor whiteColor];
}
- (void)leftBarButtonItem:(UIBarButtonItem *)button {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)createTableView {
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.episodeTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, ScaleX * 375, ScaleY * 603) style:(UITableViewStylePlain)];
    _episodeTableView.delegate  = self;
    _episodeTableView.dataSource = self;
    [self.view addSubview:_episodeTableView];
    [_episodeTableView registerClass:[ZGLEpisodeCell class] forCellReuseIdentifier:@"ZGLEpisodeVC_ZGLEpisodeCell"];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    if (_modelArr.count == 0) {
        return 1;
    }
    return _modelArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ZGLEpisodeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ZGLEpisodeVC_ZGLEpisodeCell"];
    if (_modelArr.count > 0) {
        cell.subModel = _modelArr[indexPath.section];
    }
    return cell;
}
- (void)setModelArr:(NSMutableArray *)modelArr {
    if (_modelArr != modelArr) {
        _modelArr = modelArr;
    }
    [_episodeTableView reloadData];
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return ScaleY * 380;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createTableView];
    [self setNavigationBar];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
